<?php 
	session_start();
	header("Content-type:text/html;charset=utf-8");

	$user_name = $_SESSION['user_name'];
    include "../../lib/DB.php";
    $db = new DB();
    $cat = $db->table('classification')->select();

    //购物车商品
    $goods = $db->table($user_name)->select();

    $insert = [
        'order_no' => time(),
        'created_at' => date('Y-m-d H:i:s',time()),
        'total' => array_sum(array_column($goods,'price')),
        'user_name' => $user_name,
        'goods_ids' => join(",",array_column($goods,'title'))
    ];
    $db->table('orders')->insert($insert);
    //清空购物车
    $db->table($user_name)->delete();

    echo "<script>alert('结算成功');location='index.php'</script>";
    die;

 ?>